package ase.assignment.sts.rmi.server;

import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.Naming;

import ase.assignment.sts.utils.STSConstants;

public class RMIServerStarter {

	public static void main(String args[]) {

		System.out.println(System.getProperty("java.security.policy"));

		try {

			// set the security manager
			// if (System.getSecurityManager() == null) {
			// System.setSecurityManager(new SecurityManager());
			// }
			// HandlerFactory factory = new HandlerFactoryRMIServerImpl();
			// CustomerHandler customer = factory.getCustomerHandler();
			// CustomerHandler customerStub =
			// (CustomerHandler) UnicastRemoteObject.exportObject(customer, 0);
			// Registry registry = LocateRegistry.getRegistry();
			// System.out.println("RMI Server before binding");
			// registry.rebind(STSConstants.RMI_NAME_CUSTOMER, customerStub);

		/*	System.setSecurityManager(new RMISecurityManager());
			Registry registry = LocateRegistry.getRegistry();
			registry.rebind(STSConstants.RMI_NAME_CUSTOMER,
					new CustomerHandlerRMIServerImpl());
			registry.rebind(STSConstants.RMI_NAME_PORTFOLIO,
					new PortfolioHandlerRMIServerImpl());
			registry.rebind(STSConstants.RMI_NAME_STOCK,
					new StockHandlerRMIServerImpl());
*/

			Naming.rebind(STSConstants.RMI_NAME_CUSTOMER,
					new CustomerHandlerRMIServerImpl());
			Naming.rebind(STSConstants.RMI_NAME_PORTFOLIO,
					new PortfolioHandlerRMIServerImpl());
			Naming.rebind(STSConstants.RMI_NAME_STOCK,
					new StockHandlerRMIServerImpl());
				
			System.out.println("RMI Server running.....");

		}

		catch (RemoteException re) {
			System.out.println("Remote exception: " + re.toString());
		}
		catch(Exception e){
			System.out.println("Remote Server launching error: " + e.toString());	
		}

	}

}
